#!/usr/bin/env closh-zero.jar
;; -*- clojure -*-


;; Automation TODOs
;; - At the beginning ask for the new version and automate updating versions:
;;   - npm version
;;   - git tag
;;   - hash in README
;; - Automate Github release by using Github API
;;   - Create release and copy changelog contents
;;   - Upload closh-zero.jar artifact

(defcmd wait-for-enter []
  (print "Press Enter to continue: ")
  (flush)
  (read-line)
  (println))

; (let [current-branch (sh-str git rev-parse --abbrev-ref HEAD)]
;   (when (not= current-branch "master")
;     (sh echo Currently on the branch (str "`" current-branch "`") \;
;         echo Please switch to "`master`", make sure it is up-to-date and retry release \;
;         echo Exiting... \;
;         exit 1)))

echo Runing tests...
npm run test || echo Tests failed - Exiting && exit 1
echo

echo Update changelog - Collect all changes and create a new section for the release in CHANGELOG.md
wait-for-enter

echo Update version in package.json
wait-for-enter

echo Update version in resources/CLOSH_VERSION
wait-for-enter

echo Create git tag
echo git tag v0.x.x
wait-for-enter

echo Update hash in readme to the tagged commit with this hash:
git rev-parse HEAD
wait-for-enter

echo Bulding the JAR...
npm run pkg-java
echo

echo Draft a release on Github - copy the notes from Changelog
echo Visit "https://github.com/dundalek/closh/releases/new"
echo Upload closh-zero.jar to Github release
wait-for-enter

echo Pushing branch and tag...
git push && git push --tags

echo Publishing npm publish
npm publish
echo

echo Release done - spread the word in chats!
